	package com.mellarius.Adaptor;

import java.util.ArrayList;
import java.util.List;
import com.helper.RegPelagueHlp;
import com.mellarius.R;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

public class RemoveTreatmentAdaptor extends ArrayAdapter<RegPelagueHlp> {


		List<RegPelagueHlp> regPelagues = new ArrayList<RegPelagueHlp>();
		List <PlanetViewHolder> cbList = new ArrayList<PlanetViewHolder>();
		Context context;
		View convertView;
		int size;


		public RemoveTreatmentAdaptor(Context context, List<RegPelagueHlp> resource) {
			super(context, R.layout.inner_fragment_remove_treatment, resource);
			// TODO Auto-generated constructor stub
			this.context = context;
			this.regPelagues = resource;

		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {

			RegPelagueHlp regPelague = (RegPelagueHlp) this.getItem(position);
			TextView name;
			TextView date;
			CheckBox cb;
			if (convertView == null) {
				LayoutInflater inflater = ((Activity) context).getLayoutInflater();
				convertView = inflater.inflate(R.layout.inner_fragment_remove_treatment, parent, false);
				name = (TextView) convertView.findViewById(R.id.textColmeiaRemoveTreatment);
				date = (TextView) convertView.findViewById(R.id.textDataRemoveTreatment);
				cb = (CheckBox) convertView.findViewById(R.id.checkBoxRemoveTreatment);
				convertView.setTag(new PlanetViewHolder(name,date, cb));
				cb.setOnClickListener(new View.OnClickListener() {
					public void onClick(View v) {
						CheckBox cb = (CheckBox) v;
						RegPelagueHlp regPelague = (RegPelagueHlp) cb.getTag();
						if (cb.isChecked()) {
							regPelague.setChecked(cb.isChecked());
						} else {
							regPelague.setChecked(false);
						}
					}
				});
			} else {
				// Because we use a ViewHolder, we avoid having to call
				// findViewById().
				PlanetViewHolder viewHolder = (PlanetViewHolder) convertView.getTag();	
				cb = viewHolder.getCheckBox();
				name = viewHolder.getName();
				date = viewHolder.getDate();
				
			}
			// Tag the CheckBox with the Hive it is displaying, so that we can
			// access the hive in onClick() when the CheckBox is toggled.
			cb.setTag(regPelague);
			// Display hive data
			name.setText(regPelague.getColmeia());
			date.setText(regPelague.getDate());
			cb.setChecked(regPelague.isChecked());

			
			return convertView;
		}


		/** Holds child views for one row. */
		private static class PlanetViewHolder {
			private CheckBox checkBox;
			private TextView name;
			private TextView date;

			public PlanetViewHolder(TextView name,TextView date, CheckBox checkBox) {
				this.checkBox = checkBox;
				this.name = name;
				this.date = date;
			}

			public CheckBox getCheckBox() {
				return checkBox;
			}

			public TextView getName() {
				return name;
			}
			public TextView getDate() {
				return date;
			}
		}
	}
